﻿//#include <iostream>
//#include <iomanip> 
//using namespace std;
//class Date
//{
//protected:
//	int year, month, day;
//public:
//	Date() {};
//	Date(int y, int m, int d) :year(y), month(m), day(d) {};
//};
//class Time
//{
//protected:
//	int hour, min_, second;
//public:
//	Time() {};
//	Time(int h, int min, int s) :hour(h), min_(min), second(s) {};
//};
//class Work :public Date, public Time
//{
//protected:
//	int id_;
//public:
//	Work() { };
//	Work(int y, int m, int d, int h, int min, int s, int id) :Date(y, m, d), Time(h, min, s), id_(id) {};
//	friend bool before(const Work& w1, const Work& w2);
//	void print()
//	{
//		cout << "The urgent Work is No." << id_ << ": " << year << "/" << setw(2) << setfill('0') << month << "/" << setw(2) << setfill('0') << day << " " << setw(2) << setfill('0') << hour << ":" << setw(2) << setfill('0') << min_ << ":" << setw(2) << setfill('0') << second << endl;
//	}
//};
//bool before(const Work& w1, const Work& w2)
//{
//	if (w1.year < w2.year || (w1.year == w2.year && w1.month < w2.month) ||
//		(w1.year == w2.year && w1.month == w2.month && w1.day < w2.day) ||
//		(w1.year == w2.year && w1.month == w2.month && w1.day == w2.day && w1.hour < w2.hour)
//		|| (w1.year == w2.year && w1.month == w2.month && w1.day == w2.day && w1.hour == w2.hour && w1.min_ < w2.min_)
//		|| (w1.year == w2.year && w1.month == w2.month && w1.day == w2.day && w1.hour == w2.hour && w1.min_ == w2.min_ && w1.second < w2.second))
//	{
//		return true;
//	}
//	else
//		return false;
//}
//int main()
//{
//	int id, y, m, d, h, min, s, i = 0;
//	Work p[100];
//	while (1)
//	{
//		cin >> id;
//		if (id == 0)
//			break;
//		else
//		{
//			cin >> y >> m >> d >> h >> min >> s;
//			Work work(y, m, d, h, min, s, id);
//			p[i] = work;
//			i++;
//		}
//	}
//	int j, k;
//	Work workmin = p[0];
//	for (j = 1; j < i; j++)
//	{
//		if (before(p[j], workmin))
//			workmin = p[j];
//	}
//	workmin.print();
//	return 0;
//}
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip> 
using namespace std;
class CPeople
{
protected:
	string id, name;
public:
	CPeople() {};
	CPeople(string id_,string name_):id(id_),name(name_) {};
};
class  CInternetUser:virtual public CPeople
{
protected:
	string i_mm_,ib_id_, ib_mm_;
public:
	CInternetUser() {};
	CInternetUser(string id_, string name_,string i_mm, string ib_id, string ib_mm) :CPeople(id_,name_), i_mm_(i_mm), ib_id_(ib_id), ib_mm_(ib_mm) { };
	bool panduan(string ib_id, string ib_mm)
	{
		if (id == ib_id&& i_mm_ == ib_mm)
			return true;
		else
			return false;
	}
};

class CBankCustomer :virtual public CPeople
{
protected:
	double balance=0;
public:
	CBankCustomer() {};
	CBankCustomer(string id_, string name_) :CPeople(id_, name_),balance(0) {};
	void  deposit(double money)
	{
		balance = balance + money;
	}
	void  withdraw(double money)
	{
		balance = balance - money;
	}
};

class CInternetBankCustomer :public CInternetUser, public  CBankCustomer
{
protected:
	double interbalance=0,prebalance=0, toearning=0,todayinterest=0, preinterest=0;
	char op_;
	double money_;
public:
	CInternetBankCustomer(string id_, string name_,  string i_mm, string ib_id, string ib_mm) :CPeople(id_, name_),
		CInternetUser(id_, name_,i_mm,ib_id, ib_mm), CBankCustomer(id_, name_) {};
	void setmoney(double money)
	{
		money_ = money;
	}
	void setop(char op,double interest)
	{
		op_ = op;
		if (op == 'D'|| op == 'd')//直接向银行帐户存款
		{
			balance = balance + money_;
			cout << "Name: " << CPeople::name << " ID: " << CPeople::id<< endl;
			cout << "Bank balance: "  << CBankCustomer::balance << endl;
			cout << "Internet bank balance: " << interbalance << endl<<"\n";
		}
		else if (op == 's'||op == 'S') //从银行向互联网金融帐户存入
		{
			if (balance == 0)
			{
				cout << "Bank balance not enough" << endl;
			}
			else
			{
				interbalance = interbalance + money_ + prebalance * preinterest * 0.0001;
				balance = balance - money_;
				cout << "Name: " << CPeople::name << " ID: " << CPeople::id << endl;
				cout << "Bank balance: " << CBankCustomer::balance << endl;
				cout << "Internet bank balance: " << interbalance << endl << "\n";
				prebalance = interbalance;
				preinterest = interest;
			}
		}
		else if (op == 'T' || op == 't')//从互联网金融转入银行帐户
		{
			if (interbalance == 0)
			{
				cout << "Internet bank balance not enough" << endl;
			}
			else 
			{
				interbalance = interbalance - money_ + prebalance * preinterest * 0.0001;
				balance = balance + money_;
				cout << "Name: " << CPeople::name << " ID: " << CPeople::id << endl;
				cout << "Bank balance: " << CBankCustomer::balance << endl;
				cout << "Internet bank balance: " << interbalance << endl << "\n";
				prebalance = interbalance;
				preinterest = interest;
			}
		}
		else if(op == 'W' || op == 'w')//直接从银行帐户取款
		{
			if (balance == 0)
			{
				cout << "Bank balance not enough" << endl;
			}
			balance = balance - money_;
			interbalance = interbalance + prebalance * preinterest * 0.0001;
			cout << "Name: " << CPeople::name << " ID: " << CPeople::id << endl;
			cout << "Bank balance: " << CBankCustomer::balance << endl;
			cout << "Internet bank balance: "  << interbalance << endl << "\n";
			prebalance = interbalance;
			preinterest = interest;
		}
	}
		bool panduan(string b_id,string nameb)
		{
			if (CInternetUser::name == nameb && CInternetUser::id== b_id)
				return true;
			else
				return false;
		}
		
};
int main()
{
	int t, n;
	string namei, i_id, i_mm, nameb, b_id, ib_id, ib_mm;
	double money, interest;
	char op;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> namei >> i_id >> i_mm >> nameb >> b_id >> ib_id >> ib_mm ;
		CInternetUser cInternetUser(i_id, namei, i_mm, ib_id, ib_mm);
		CBankCustomer cBankCustomer(b_id, nameb);	
		CInternetBankCustomer  ib_user(i_id, namei, i_mm, ib_id, ib_mm);
		if(!cInternetUser.panduan(ib_id, ib_mm)|| !ib_user.panduan(b_id, nameb))
		{
			cout << "Password or ID incorrect" << endl ;
		}
		else
		{
			cin >> n;
			for (int j = 0; j < n; j++)
			{
				cin>> op >> money >> interest;
				ib_user.setmoney(money);
				ib_user.setop(op,interest);
			}
		}
		
	}
	return 0;
}
//#include <iostream>
//using namespace std;
//class Journey
//{
//protected:
//	int jid_;
//	double jscore_ = 0;
//public:
//	Journey() {};
//	Journey(int jid) :jid_(jid), jscore_(0) {};
//};
//class Credit
//{
//protected:
//	int cid_;
//	double cscore_;
//	string name_;
//	float bill;
//	int money_;
//public:
//	Credit() {};
//	Credit(string name, int cid, int money) :name_(name), cid_(cid), money_(money), cscore_(0), bill(0) {};
//};
//class Journeycredit :public Journey, public Credit
//{
//public:
//	Journeycredit() {};
//	Journeycredit(int jid, string name, int cid, int money) :Journey(jid), Credit(name, cid, money) {};
//	void display(char type, double change)
//	{
//		if (type == 'o' )
//		{
//			bill = bill + change;
//			jscore_ = jscore_ + change;
//			cscore_ = cscore_ + change;
//		}
//		else if (type == 'c' && change > money_)//信用卡消费金额m，若超额度，则不做操作；否则，账单金额+m，额度-m，信用卡积分按消费金额累加。
//		{
//			cscore_ = cscore_ ;
//			bill = bill ;
//			money_ = money_ ;
//		}
//		else if (type == 'c' && change < money_)
//		{
//			cscore_ = cscore_ + change;
//			bill = bill + change;
//			money_ = money_ - change;
//			cout << cscore_ << endl;
//		}
//		else if (type == 'q')
//		{
//			cscore_ = cscore_ - change;
//			bill = bill - change;
//			cout << cscore_ << endl;
//		}
//		else
//		{
//			jscore_ = jscore_ + (change / 2);
//			cscore_ = cscore_ - change;
//			cout << cscore_ << endl;
//		}
//	}
//	void print()
//	{
//		cout << jid_ << " " << (int)jscore_ << endl << cid_ << " " << name_ << " " << bill << " " << (int)cscore_ << endl;
//	}
//};
//int main()
//{
//	int jid, cid, money, n;
//	string name;
//	char type;
//	double change;
//	cin >> jid >> cid >> name >> money >> n;
//	Journeycredit journeycredit(jid, name, cid, money);
//	for (int i = 0; i < n; i++)
//	{
//		cin >> type >> change;
//		journeycredit.display(type, change);
//	}
//	journeycredit.print();
//	return 0;
//}